import "package:http/http.dart" as http;
import 'dart:convert';

/// https://httpbin.org/ip  返回IP地址

// 代码摘自B站视频： https://www.bilibili.com/video/BV1rN411Z7JH
// https://pub.flutter-io.cn/packages/http
// `http: ^0.13.4` 这个版本的http请求方式与视频中讲解的不同！ 具体参考上面的http库文档

Future getIpAddress() async {
  var url = Uri.parse('https://httpbin.org/ip');
  var response = await http.get(url);
  String ip = jsonDecode(response.body)['origin'];
  return ip;
}

void main() async {
  try {
    var ip = await getIpAddress();
    print(ip);
  } catch(error) {
    print(error);
  }
}

